#include <FileStoreI.h>

FileStoreI::FileStoreI(const string& category) :
  _category(category)
{
}

FileStoreI::~FileStoreI()
{
}

::Yafridng::FilePrx
FileStoreI::read(const ::std::string& name,
		 ::Ice::Int num,
		 ::Ice::Int offset,
		 ::Ice::Int pieceSize,
		 const ::Ice::Current& current)
{
  FILE* fp = fopen(name.c_str(), "rb");

  if (fp == 0) {
    FileAccessException ex;
    cout << "Exception" << endl;
    ex.reason = "cannot open '" + name + "' for reading: " + strerror(errno);
    throw ex;
  }

  fseek(fp, offset, SEEK_SET);
  Identity FileIdentity;
  FileIdentity.name = IceUtil::generateUUID();
  FileIdentity.category = _category;
  return FilePrx::uncheckedCast(current.adapter->add(new FileI(fp, num, pieceSize), FileIdentity));
}
